<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function User(name, age) {
        this.age = age;
        this.name = name;
      }
      let tom = new User("tom", 22);

      let dog = { food: "鸡腿" };
      // 相当于给dog增加了age name 两个属性， call方法就可以用来制定this的指向
      User.call(dog, "kiki", 3);
      console.log(dog);

      // call 和 apply 的区别， apple使用数组的形式传递参数

      let lisi = {
        name: "lisi",
      };
      let tony = {
        name: "Tony",
      };

      function People(age, height) {
        console.log(this.name + age + height);
      }
      People.call(lisi, 22, 180);
      People.apply(tony, [11, 150]);

      // demo 数组求最大值
      let arr = [1, 2, 4, 11];

      console.log(Math.max(...arr));

      console.log(Math.max.apply(Math, arr));
    </script>
  </body>
</html>
